//
//  LDMyResumeCellMyAdvantageInAll_Row.swift
//  DingDongZP
//
//  Created by LeMac on 16/12/27.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

import UIKit



class LDMyResumeCellMyAdvantageInAll_Row: UIView {

    
    static let textViewWidth:CGFloat = LDFrame.ScreenWidth - 45
    
    enum LDMyResumeCellMyAdvantageInAll_RowType:Int {
        
        case Heightlight
        case Strength
    }
    var descText:String? {
        
        didSet{
            
            let newStr = descText?.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
            let attr = String.getAttrFormString(lineH: LDFrame.AttrLineH, text: newStr ?? "", font: LDFont.Font14)
            strengthTag?.attributedText = attr
        }
    }
    
    var title:String? {
        
        didSet{
           titleLab?.text = title
        }
    }
    
    lazy var noticeLab:UILabel = {
        
        let lab = UILabel.setDetailsLab("语音简历未录入", fontSize: 14, titleColor: LDFontColor.LightGray, Alignment: .Left)
        return lab
    }()
    
    var vocieBtnClosure:((AnyObject)->())?
    
    var dotView:UIImageView?//green_dot
    private var divideLineV:UIView?
    
    private var titleLab:UILabel?
    var strengthTag:UILabel?
    
    private var voiceImg:UIImageView?
    var voiceBtn:baseVoiceButton?
    
    var type = LDMyResumeCellMyAdvantageInAll_RowType.Heightlight
    internal var model:DDMyResumeModel? {
        
        didSet{
            updateView()
        }
    }
    
    
    init(type:LDMyResumeCellMyAdvantageInAll_RowType) {
        super.init(frame: CGRectZero)
        self.type = type
        
       
        setupView()
        
    }
    
    func updateView() {
        
        if type == .Heightlight {
            
            let titleArr = model?.highlights.map({ (obj) -> String in
                
                return obj.tag ?? ""
            })
            
            var heightStr = ""
            for (index,item) in titleArr!.enumerate() {
                
                if index == 0 {
                    
                    heightStr.appendContentsOf(item)
                } else {
                    heightStr.appendContentsOf(" | " + item)
                }
            }
            
            //String.getAttrFormString(lineH: 8, text: heightStr, font: LDFont.Font14)
            if heightStr.characters.count > 0 {
                descText = heightStr
            } else {
                descText = "未录入亮点标签"
            }
            
            if model?.audiohighlights_isset == "1" {
                
                noticeLab.hidden = true
                voiceBtn?.timeLab?.text = String.init(format: "%@'", model?.audiohighlights_duration ?? "0")
            } else {
                
                voiceBtn?.hidden = true
                noticeLab.hidden = false
            }
            
        } else {
            
            if model?.audiomystrengths_isset == "1" {
                
                noticeLab.hidden = true
                voiceBtn?.timeLab?.text = String.init(format: "%@'", model?.audiomystrengths_duration ?? "0")
            } else {
                
                voiceBtn?.hidden = true
                noticeLab.hidden = false
                //                noticeLab.text = "语音简历未录入"
            }
            descText = model?.mystrengthstext ?? "未录入优势文本"
            
        }
        
//        self.layoutSubviews()
        
        
    }
    
    
    class func getTagDesc(model:DDMyResumeModel?) -> String {
        
        let titleArr = model?.highlights.map({ (obj) -> String in
            
            return obj.tag ?? ""
        })
        
        var heightStr = ""
        for (index,item) in titleArr!.enumerate() {
            
            if index == 0 {
                
                heightStr.appendContentsOf(item)
            } else {
                heightStr.appendContentsOf(" | " + item)
            }
        }
        
        return heightStr
    }
    
    func setupView() {
        
        dotView = UIImageView(image: UIImage(named: "green_dot"))
        
        
        titleLab = UILabel.setDetailsLab("亮点", fontSize: 16, titleColor: LDFontColor.BlackLight, Alignment: .Left)
        
        strengthTag = UILabel.setDetailsLab("", fontSize: 14, titleColor: LDFontColor.DeepGray, Alignment: .Left)
        strengthTag?.numberOfLines = 0
        
        
        voiceImg = UIImageView.init(image:UIImage(named: "话筒"))
        voiceBtn = baseVoiceButton.init(frame: CGRectMake(0, 0, 120, 30))
        
        voiceBtn?.bk_whenTapped({ [weak self] in
          
            if self?.vocieBtnClosure != nil {
                
                self?.vocieBtnClosure!(self!)
            }
        })
        
        addSubview(noticeLab)
        addSubview(dotView!)
        addSubview(titleLab!)
        addSubview(strengthTag!)
        addSubview(voiceImg!)
        addSubview(voiceBtn!)
        
        
        
        dotView?.snp_makeConstraints(closure: { (make) in
            make.top.equalTo(18/2)
            make.left.equalTo(LDMargin_V*3)
            make.width.height.equalTo(10)
        })
        
        
        titleLab?.snp_makeConstraints(closure: { (make) in
            make.centerY.equalTo(dotView!.snp_centerY)
            make.left.equalTo(dotView!.snp_right).offset(LDMargin_V*3)
            make.height.equalTo(18)
        })
        
        strengthTag?.snp_makeConstraints(closure: { (make) in
            
            make.top.equalTo(titleLab!.snp_bottom).offset(LDMargin_V*2)
            make.left.equalTo(titleLab!)
//            make.right.equalTo(-LDMargin_V)
            make.width.equalTo(LDFrame.ScreenWidth - 45)
            
        })
        
        voiceImg?.snp_makeConstraints(closure: { (make) in
            
            make.top.equalTo(strengthTag!.snp_bottom).offset(LDMargin_V*2)
            make.left.equalTo(titleLab!)
            make.height.width.equalTo(24)
        })
        
        voiceBtn?.snp_makeConstraints(closure: { (make) in
            make.centerY.equalTo(voiceImg!)
            make.left.equalTo(voiceImg!.snp_right).offset(LDMargin_V*3)
            make.height.equalTo(28)
            make.width.equalTo(120)
        })
        
        noticeLab.snp_makeConstraints(closure: { (make) in
            make.centerY.equalTo(voiceImg!)
            make.left.equalTo(voiceImg!.snp_right).offset(20)
            make.height.equalTo(28)
            make.width.equalTo(120)
        })
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

}
